package showtime.framework.engine.input
{
	import showtime.framework.engine.World2D;

	public class InputDevice
	{		
		public var enabled:Boolean = false;
		
		protected var keys:Vector.<int> = null;		
		
		public function InputDevice(inputs:int)
		{
			keys = new Vector.<int>(inputs, true);
			enabled = true;
		}
		
		public function down(key:int):Boolean
		{
			return enabled ? keys[key] > 0 : false;
		}
		
		public function pressed(key:int):Boolean
		{
			return enabled ? keys[key] >= World2D.then && keys[key] < World2D.now && World2D.then > 0 : false;
		}
		
		public function released(key:int):Boolean
		{
			return enabled ? keys[key] <= -World2D.then && keys[key] > -World2D.now && World2D.then > 0 : false;
		}
		
		public function releaseAll():void
		{
			for (var index:int = 0; index < keys.length; index++)
			{
				if (keys[index] > 0)
				{
					keys[index] = -World2D.now;
				}
			}
		}
	}
}